import java.util.Random;

/** {@code Cards}类 对一副扑克牌的抽象 */
public class Cards {
    /** 一副德州扑克有52张牌 */
    public static final int MAX = 52;
    /** 扑克牌数组 */
    private Card[] card = new Card[MAX];
    /** 下张牌的抽取位置 */
    private int index = 0;
    /** 随机数类 */
    private Random rand = new Random();

    /** 构造一副德州扑克牌 */
    public Cards() {
        for (int i = 0; i < MAX; i++) {// 生成52张牌
            card[i] = new Card(i);
        }
        reset();
    }

    /** 重置该副牌 */
    public void reset() {
        index = 0;
        shuffle();
    }

    /** 抽取并返回一张扑克牌 */
    public Card getCard() {
        return card[index++];
    }

    /** 设定下张牌的抽取位置为 i */
    public void setIndex(int i) {
        index = i;
    }

    /** 洗牌 */
    private void shuffle() {
        for (int i = Cards.MAX - 1; i > 0; i--) {
            int j = rand.nextInt(i + 1);// [0,i+1)==>[0,i]
            Card temp = card[i];
            card[i] = card[j];
            card[j] = temp;
        }
    }
}
